//添加好友
let markId = getUrlString('markid');
$('#goAddFrd').click(function () {
    window.location.href = 'dancool://web=https://api.odancool.com/weixinapp/view/messages/searchUser.html?markid='+markId
});

//群组
$('#goGroupList').click(function () {
    window.location.href = 'dancool://web=https://api.odancool.com/weixinapp/view/messages/groupList.html?markid='+markId
});

//黑名单
$('#goBlackList').click(function () {
    window.location.href = 'dancool://blacklist='+markId
});

let mRefresh = new MiniRefresh({
    container: '#mrefresh', //这里是插件的容器ID
    down: {
        isAuto: false,
        callback: function () {
            // 下拉后的回调事件 ，你可以在这里执行你的后台请求数据函数，达到刷新数据的作用
           window.location.reload();
        }
    }
    ,
    up: {
        isAuto: true,
        callback: function () {
            // 向上拉后的回调事件
            // getnative('dancool://message_getConversationList=1');
            mRefresh.endUpLoading(true);
        }
    }
});

getFriendInviteList();

function getFriendInviteList (){
    var data = {
        'markid':markId,
        'status':'1'
    };
    getData('get','/niu/apiv3/weibo_friend.php?method=getFriendInviteList',data,function (data) {
        console.log(data);
        let timer = null;
        if (data.datacount > '0'){
            $('#number').html(data.datacount).show();
        }else {
            $('#number').hide();
        }
        $('#verifyMsg').click(function () {
            clearInterval(timer);
            window.location.href = 'dancool://web=https://api.odancool.com/weixinapp/view/messages/verifyMsg.html?markid='+markId
        })
    })
}

function getFrdList () {
    getData('post','/niu/apiv3/weibo_friend.php?method=getFriendList',{'markid':markId},function (data) {
        console.log(data);
        if (data.datacount === '0'){
            $('#noFrd').show()
        } else {
            $('#noFrd').hide();
            let append = '';
            $(data.data).each(function () {
                append += ' <li>' +
                    '<input type="hidden" class="name" value="djuser_'+this.frienduserid+'">'+
                    '            <div class="left">' +
                    '                <img src="'+this.faceurl+'" alt="">' +
                    '            </div>' +
                    '            <div class="right">' ;
                if(this.markusername === ''){
                    append+= '                <span>'+this.nick+'</span>' ;
                }else {
                    append+= '                <span>'+this.markusername+'</span>' ;
                }
                   append+= '            </div>' +
                    '        </li>'
            });
            $('#conversationList').append(append);
            mRefresh.scrollTo('5','30');
            $('#conversationList li').click(function () {
                let toUserName = $(this).find('.name').val();
                getnative('dancool://message_enterSingleConversation='+toUserName+'');
                window.location.href = 'dancool://fullweb=https://api.odancool.com/weixinapp/view/messages/sessionList.html?toUserName='+toUserName
            })
        }
    })
}

//获取自己的好友列表
getFrdList();
// getnative('dancool://message_getFriendList=1');

function getnative(actionurl) {
    var u = navigator.userAgent;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if (isiOS) {
        window.webkit.messageHandlers.getnative.postMessage(actionurl);
    }else {
        ikags.getnative(actionurl)
    }
}

function jsnativeresult(tag1,tag2,tag3) {


}